#include <gnome.h>
#include "list_model.h"

GtkTreeModel *
create_model_Users (void)
{
  GtkListStore  *listStore;
  GtkTreeIter    iter;

  listStore = gtk_list_store_new (NUM_COLS, 
		  G_TYPE_STRING, 
		  G_TYPE_STRING, 
		  G_TYPE_STRING, 
		  G_TYPE_STRING, 
		  G_TYPE_INT, 
		  G_TYPE_INT);

  return GTK_TREE_MODEL(listStore);
}

GtkWidget *
create_view_and_model_Users (void)
{
  GtkTreeViewColumn   *col;
  GtkCellRenderer     *renderer;
  GtkWidget           *view;
  GtkTreeModel        *model;

  view = gtk_tree_view_new();

  /* --- Column #1 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Site");

  /* pack tree view column into tree view */
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);

  renderer = gtk_cell_renderer_text_new();

  /* pack cell renderer into tree view column */
  gtk_tree_view_column_pack_start(col, renderer, TRUE);

  /* connect 'text' property of the cell renderer to
   *  model column that contains the first name */
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_SITE);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);

  /* --- Column #2 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Referer");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_REF);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);

  /* --- Column #3 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Entry Page");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_ENTRY);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);

  /* --- Column #4 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Start Time");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_START);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);
  
  /* --- Column #5 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Path Length");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_PATH);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);

  /* --- Column #6 --- */
  col = gtk_tree_view_column_new();
  gtk_tree_view_column_set_title(col, "Site Accesses");
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_ACC);
  gtk_tree_view_column_set_min_width (col, 0);
  g_object_set (G_OBJECT(col), "resizable", TRUE, NULL);
    
  model = create_model_Users();
  gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
  g_object_unref(model); /* destroy model automatically with view */
  gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
                              GTK_SELECTION_NONE);

  return view;
}
